//twopts.txt - Like basic monst, but this character spends all its time oscillating 
// between two nav points.
// Memory Cells:
//   Cell 0 - Ability. If 1, scythes.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	 Cell 3 - The nav point the character marches to. If -1, stand still
//   Cell 4 - If 0, this patrols. If 1, stays put.

begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short adjust = 0;
short last_abil;
short did_sighting = 0;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();
	
	set_walk_speed(ME,22);
	
	set_aggression(ME,10);

		set_resistance(ME,0,40);
		set_resistance(ME,1,40);
		set_resistance(ME,2,40);
		set_resistance(ME,3,40);

		if (creature_type(ME) == 158) {
			set_name(ME,"Scything Beta");
			set_boss_level(ME,1);
			}

		if (get_level(ME) < 20)
			set_level(ME,20);
			
	if (gf(28,15) > 34) {
		set_summon_level(ME,1);
		
		if (creature_type(ME) == 158)
			set_name(ME,"Decaying Beta");
		if (creature_type(ME) == 68)
			set_name(ME,"Decaying Podling");
		if (creature_type(ME) == 69)
			set_name(ME,"Decaying Podling");
		if (creature_type(ME) == 162)
			set_name(ME,"Decaying Glaahk");
		}
		
	break;

beginstate DEAD_STATE;
	inc_flag(28,15,1);
	
break;

beginstate START_STATE; 

	if ((adjust == 0) && (gf(28,4) > 0)) {
		adjust = 1;
		set_resistance(ME,0,0);
		set_resistance(ME,1,0);
		set_resistance(ME,2,0);
		set_resistance(ME,3,0);
		}


	
	// if I have a target for some reason, go attack it
	if (who_shot_me() >= 0) {
		did_sighting = 1;
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {

		if ((get_attitude(ME) >= 10) && (did_sighting == 0)) {
			did_sighting = 1;
			if (has_item_equip(376) == FALSE) {
				print_named_str(ME,"stares at you. Then it attacks!");
				if (gf(28,25) == 0) {
					sf(28,25,1);
					begin_talk_mode(30);
					}
					
				}
				else if (get_stat(20) < 11) {
					print_named_str(ME,"looks at your necklace, but you fail to calm it.");
					if (gf(28,23) == 0) {
						sf(28,23,1);
						begin_talk_mode(31);
						}
					}
					else {
						print_named_str(ME,"looks at your necklace. You are able to calm it.");
						set_attitude(1000 + what_group_in(ME),4);
						set_foe_target(ME,-1);
						if (gf(28,24) == 0) {
							sf(28,24,1);
							begin_talk_mode(32);
							}
						end();
						}
			}

		do_attack();
		set_state(3);
		}

	if (gf(28,6) > 0) {
		if (my_dist_from_start() > 2)
			return_to_start(ME,2);
		}
		else if (get_memory_cell(4) == 0) {
			if (gf(28,16) == 0) {
				if (dist_to_nav_point(ME,get_memory_cell(3)) >= 3)
					approach_nav_point(ME,get_memory_cell(3),2);	
				}
				else return_to_start(ME,2);
			}
			else {
				if (dist_to_nav_point(ME,get_memory_cell(3)) >= 3)
					approach_nav_point(ME,get_memory_cell(3),2);	
				}

		
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((get_memory_cell(0) > 0) && (is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 1)) {
		run_char_animation(2,1,35);	
	
			print_named_str(ME,"spins around, cleaving the air with a mighty blow.");
			damage_nearby(get_ran(get_level(ME) + get_attack_bonus(ME),1,8),3,0,0);
			pc_heard_sound_delay(3,100);				
			spray_missiles(15,12,3);


		last_abil = get_current_tick();
		end();
		}
		
	do_attack();
break;

beginstate TALKING_STATE;
	print_str_color("The creature doesn't respond. Your necklace has calmed it.",2);
	break;